package top.yudoge.dogeeditor.db.datasource

class DataSourceManagerRegistry {

    private val managers: MutableMap<String, () -> DataSourceManager> = mutableMapOf()

    fun register(managerName: String, builder: () -> DataSourceManager) {
        if (managers.containsKey(managerName)) {
            throw IllegalArgumentException("Duplicate data source manager name [${managerName}]")
        }
        managers.put(managerName, builder)
    }

    fun newManager(managerName: String): DataSourceManager {
        if (!managers.containsKey(managerName)) {
            throw IllegalArgumentException("No such data source manager [${managerName}]")
        }

        return managers[managerName]!!.invoke()
    }

}